package com.sy.controller;

import com.sy.entity.User;
import com.sy.service.UserService;
import com.sy.util.JwtUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * Created by 时宇 on 2021-08-01 19:20
 */
@RestController
@CrossOrigin
public class Usercontroller {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public User login(@RequestBody User user){
        User login = userService.login(user);
        if(login!=null){
            login.setToken(JwtUtil.createToken());
            return login;
        }
        return null;
    }

    @GetMapping("/checkToken")
    public Boolean checkToken(HttpServletRequest request){
        String token = request.getHeader("token");
        return JwtUtil.checkToken(token);
    }

}
